<?php

if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );
	
	// 用户的地址表
class OrderAdd_model extends MY_Model {
	var $table = 'order_address';
	public function __construct() {
		parent::__construct ();
	}
	
	/**
	 * 用户的地址表
	 *
	 * @param array $data        	
	 * @return integer
	 */
	public function add($data) {
		return $this->insert ( $data );
	}
	
	/**
	 * 取得所有地址by用户id
	 *
	 * @param array $config        	
	 * @param array $like        	
	 * @return array
	 */
	public function getAddressAll($id) {
		//这里加了个网点名称，是IOS要求的。名称为wangdian
		$query =$this->db
			->select('oa.*,ae.address as addressShort')
			->from('order_address oa')
			->join('areas_enabled ae','oa.areas_id=ae.id','left')
			->where(array('user_id' =>$id))
			->get();
		return $query->result_array();
	}
	
	/**
	 * 查找单条信息by $id
	 *
	 * @param integer $id
	 * @return array
	 */
	public function findAddress($id) {
		return $this->get_row(array('id'=>$id));
	}
	
	/**
	 * 删除单条地址
	 *
	 * @param integer 
	 * @return integer
	 */
	public function deleteAgent($ids) {
		return $this->delete(array('id'=>$ids));
	}
	
	
	/**
	 * 更新一条信息
	 *
	 * @param array $data
	 * @param integer $id
	 * @return integer
	 */
	public function updateAddress($data, $id) {
		return $this->update($data, array('id'=>$id));
	}
	
	/**
	 * 查找单条信息by
	 *
	 * @param integer $id
	 * @return array
	 */
	public function findAddByArsid($id) {
		return $this->get_row(array('areas_id'=>$id));
	}
	
	
	/**
	 * 取得所有地址by地址id
	 *
	 * @param array $config
	 * @param array $like
	 * @return array
	 */
	public function getAddAllByid($id) {
		$query =$this->db
		->select('oa.*,ae.address as address2,a.description')
		->from('order_address oa')
		->join('areas_enabled ae','oa.areas_id=ae.id','left')
		->join('areas a','ae.district_id=a.id','left')
		->where(array('oa.id' =>$id))
		->get();
		return $query->row_array();
	}
	
}